extern "C" {

 #include <stdint.h> 


/*
typedef struct pio_context {
	struct LCD *lcd;
	struct keypad *keypad;
} pio_context_t, pioc;

typedef struct CPU {
	pioc pio;
} CPU_t;

typedef struct CALC {
	CPU_t cpu;
} calc_t;

extern calc_t *calcs;

*/

typedef struct LCD {
	double write_avg, write_last;	/* Used to determine freq. of writes to the LCD */
} LCD_t;

typedef struct keypad {
	unsigned char group;
	long long last_read;
	unsigned char keys[8][8], on_pressed;
} keypad_t;

typedef struct KEYPROG {
	int vk;
	int group;
	int bit;
} keyprog_t;



typedef struct {
	char tag[4];
	int pnt;
	int size;
	unsigned char* data;
} CHUNK_t;


typedef struct {
	int version_major;
	int version_minor;
	int version_build;
	int model;
	int chunk_count;
	char author[32];
	char comment[64];	
	CHUNK_t* chunks[512];
} SAVESTATE_t;


//calc_t *calc_new(void);
//calc_t *calc_free(void);

//int calc_run_thread(calc_t *calc);
//void calc_load(calc_t *, const char *);
//void calc_key_press(calc_t *,int keycode);
//void calc_key_release(calc_t* ,int keycode);
//double calc_run_frame(calc_t *calc);
/*
struct TIBACKUP {
	unsigned short headersize;		// size of the header up to name, sometimes ignored
	unsigned short length1;			// data size
	unsigned char vartype;			// what type of varible
	unsigned short length2;			// data size
	unsigned short length3;			// data size
	unsigned short address;			// duplicate of data size
	
	unsigned short length1a;		// Repeats of the data length.
	unsigned char * data1;			// pointer to data

	unsigned short length2a;		// data size
	unsigned char * data2;			// pointer to data

	unsigned short length3a;		// data size
	unsigned char * data3;			// pointer to data


} __attribute__((packed));

struct TIVAR {
	unsigned short headersize;		// size of the header up to name, sometimes ignored
	unsigned short length;			// data size
	unsigned char vartype;			// what type of varible
	unsigned char name[8];			// null padded name
	unsigned char version;			// 0 83+only
	unsigned char flag;				// bit 7 is if flash 83+only
	unsigned short length2;			// duplicate of data size
	unsigned char * data;			// pointer to data
} __attribute__((packed));

struct TIFILE {
	unsigned char sig[8];
	unsigned char subsig[3];
	unsigned char comment[42];
	unsigned short length;
	TIVAR_t * var;
	unsigned short chksum;
	int model;
	int type;
	ROM_t * rom;
	TIFLASH_t * flash;
	SAVESTATE_t* save;
	TIBACKUP_t* backup;
};

LINK_ERR vlink_send_var(CPU_t*, TIFILE_t*, SEND_FLAG);
TIFILE_t * importvar(char *);
void FreeTiFile(TIFILE_t *);
*/
// Destination flags
typedef enum {
	SEND_CUR,					/* sends based on current flag settings */
	SEND_RAM,					/* sends to RAM, regardless of flag settings */
	SEND_ARC					/* sends to archive, regardless of flag settings */
} SEND_FLAG;

const char CalcModelTxt[][16]
= {	"???",
	"TI-82",
	"TI-83",
	"TI-85",
	"TI-86",
	"TI-73",
	"TI-83+",
	"TI-83+ SE",
	"TI-84+",
	"TI-84+ SE",
	"???"
}
;
char* Qt_calcModel(int slot);
char* Qt_calcRomVersion(int slot);

void SendFile( char* , int );
void NoThreadSend( const char*, int);

uint8_t *LCD_image(LCD_t *);

void LoadLCD(SAVESTATE_t *,LCD_t *);

int calc_key_release(int slot, int keycode);
int calc_key_press(int slot, int keycode);

//int calc_reset(calc_t*);
int calc_slot_new(void);
u_int calc_count(void);
int calc_reset(int);
int calc_run_frame(int);
int calc_run_seconds(int, double);
int calc_run_timed(int, time_t);
int calc_run_all(void);
int rom_load(int, char *);
void calc_free(int);
//uint8_t* calc_draw(calc_t *calc);
uint8_t* calc_draw(int slot);

/*
keypad_t *keypad_init(CPU_t*);
keyprog_t *keypad_key_press(CPU_t*, unsigned int vk);
keyprog_t *keypad_key_release(CPU_t*, unsigned int vk);
*/
//void Qt_calc_reset(calc_t* calc);

int Qt_getKeycode(int group, int bit);
keyprog_t* Qt_getKeyLocation(int keycode);

void WriteSave(const char * , SAVESTATE_t *, int );
SAVESTATE_t* CreateSave(char* , char* , int );
SAVESTATE_t* SaveSlot( int slot );
void FreeSave(SAVESTATE_t*);

uint8_t* Qt_savestate_init(int );
void Qt_savestate_save(char* ,char* ,char* );
void Qt_savestate_free();
}